package com.ica.model.command.util;

import java.lang.reflect.Method;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.ITelephony;

/**
 * @author   Hector
 */
public class TelephonyProxy {
	
	/**
	 * @uml.property  name="telephony"
	 * @uml.associationEnd  
	 */
	private static ITelephony telephony = null;
	
	private ITelephony getITelephonyManager(Context context) throws Exception {
		if (telephony==null) {
			TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);  
			Class<?> c = Class.forName(telephonyManager.getClass().getName());
		    Method m = c.getDeclaredMethod("getITelephony");
		    m.setAccessible(true);
		    telephony = (ITelephony) m.invoke(telephonyManager);
		}
	    return telephony;
	}
	
	public void acceptCall(Context context) throws Exception {	
		getITelephonyManager(context).answerRingingCall();
	}
	
	public void rejectCall(Context context) throws Exception {		
		getITelephonyManager(context).endCall();
	}
}
	